package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeCate;
import com.ruoyi.grape.service.IGrapeCateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 技术资料Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/cate")
public class GrapeCateController extends BaseController
{
    @Autowired
    private IGrapeCateService grapeCateService;

    /**
     * 查询技术资料列表
     */
    @PreAuthorize("@ss.hasPermi('grape:cate:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeCate grapeCate)
    {
        startPage();
        List<GrapeCate> list = grapeCateService.selectGrapeCateList(grapeCate);
        return getDataTable(list);
    }

    /**
     * 导出技术资料列表
     */
    @PreAuthorize("@ss.hasPermi('grape:cate:export')")
    @Log(title = "技术资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeCate grapeCate)
    {
        List<GrapeCate> list = grapeCateService.selectGrapeCateList(grapeCate);
        ExcelUtil<GrapeCate> util = new ExcelUtil<GrapeCate>(GrapeCate.class);
        util.exportExcel(response, list, "技术资料数据");
    }

    /**
     * 获取技术资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:cate:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(grapeCateService.selectGrapeCateByCategoryId(categoryId));
    }

    /**
     * 新增技术资料
     */
    @PreAuthorize("@ss.hasPermi('grape:cate:add')")
    @Log(title = "技术资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeCate grapeCate)
    {
        return toAjax(grapeCateService.insertGrapeCate(grapeCate));
    }

    /**
     * 修改技术资料
     */
    @PreAuthorize("@ss.hasPermi('grape:cate:edit')")
    @Log(title = "技术资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeCate grapeCate)
    {
        return toAjax(grapeCateService.updateGrapeCate(grapeCate));
    }

    /**
     * 删除技术资料
     */
    @PreAuthorize("@ss.hasPermi('grape:cate:remove')")
    @Log(title = "技术资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(grapeCateService.deleteGrapeCateByCategoryIds(categoryIds));
    }
}
